from time import sleep
import pytest
from selenium.webdriver.common.by import By


login_data = [
    {'用例编号':"login001","用例标题":"输入正确的用户名和密码,登录成功","username":"admin","password":"123456","expect":"7"},
    {'用例编号':"login002","用例标题":"输入空的用户名和密码,登录失败","username":"","password":"","expect":"登录失败，请检查您的成员名或密码是否填写正确。"},
    {'用例编号':"login003","用例标题":"输入正确的用户名和错误密码,登录成功","username":"admin","password":"666666","expect":"登录失败，请检查您的成员名或密码是否填写正确。"},
    {'用例编号':"login004","用例标题":"输入正确的用户名和空密码,登录成功","username":"admin","password":"","expect":"登录失败，请检查您的成员名或密码是否填写正确。"},
]
@pytest.mark.parametrize("abc",login_data)
def test_login_001(get_driver,abc):
    driver = get_driver
    driver.find_element(By.ID,"account").send_keys(abc["username"])
    driver.find_element(By.ID,"password").send_keys(abc["password"])
    driver.find_element(By.ID,"submit").click()
    sleep(3)
    if abc["expect"]=="7":
        assert_text = driver.find_element(By.ID,"s-menu-superadmin").get_attribute("data-order")
        assert assert_text == abc["expect"],"异常文本，查询失败"
    else:
        assert_text = driver.find_element(By.XPATH,'/html/body/div[2]/div/div/div[1]/div').text
        assert assert_text == abc["expect"],"异常文本。查询失败"